<?php

interface IVisitor{
    public function visitCommonEmployee(CommonEmployee $commonEmployee);
    public function visitManager(Manager $manager);
}
interface ITotalVisitor extends IVisitor{
    public function totalSalary();
}

interface IShowVisitor extends IVisitor{
    public function report();
}

class TotalVisitor implements  ITotalVisitor{
    private $total_manager=0;
    private $total_common=0;

    public function visitCommonEmployee(CommonEmployee $commonEmployee){
        $this->total_manager=$this->total_manager+$commonEmployee->getSalary();
    }

    public function visitManager(Manager $manager){
        $this->total_common=$this->total_common+$manager->getSalary();
    }

    public function totalSalary()
    {
       echo "公司总工资为：".($this->total_common+$this->total_manager)."元";
    }

}
class ShowVisitor implements  IShowVisitor{
    private $info='';

    public function visitCommonEmployee(CommonEmployee $commonEmployee){
        $this->info=$this->info."".$this->getBasicInfo($commonEmployee)."".$commonEmployee->getJob()."</br>";
    }
    public function visitManager(Manager $manager){
        $this->info=$this->info."".$this->getBasicInfo($manager)."".$manager->getPerformance()."</br>";
    }

    public function report()
    {
        echo $this->info;
    }

    private function getBasicInfo(Employee $employee){
        return $employee->info;
    }

}

abstract class Employee{
    private $name;
    private $sex;
    private $salary;

    public function __construct($name,$sex,$salary){
        $this->name=$name;
        $this->sex=$sex;
        $this->salary=$salary;
    }

    public function info(){
        echo "$this->name,$this->sex,$this->salary";
    }


    public abstract function accept(IVistor $vistor);

    /**
     * @return mixed
     */
    public function getSalary()
    {
        return $this->salary;
    }

    /**
     * @param mixed $salary
     */
    public function setSalary($salary)
    {
        $this->salary = $salary;
    }

    /**
     * @return mixed
     */
    public function getSex()
    {
        return $this->sex;
    }

    /**
     * @param mixed $sex
     */
    public function setSex($sex)
    {
        $this->sex = $sex;
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param mixed $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }
}


class Manager extends  Employee{
    private $performance;

    public function getPerformance(){
        return $this->performance;
    }

    public function setPerformance($performance){
        $this->performance=$performance;
    }

    public function accept(IVistor $vistor){
        $vistor->visitManager($this);
    }
}

class CommonEmployee extends  Employee{
    private $job;
    public function getJob(){
        return $this->job;
    }
    public function setJob($job){
        $this->job=$job;
    }

    public function accept(IVistor $vistor){
        $vistor->visitCommonEmployee($this);
    }
}


//Client
/*
 新建showVistor和totalVisitor
 每个employee对象调用visist（）
 最后用showVistor找到资源
 */
?>